﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.IO;

namespace TTCaller
{
    public partial class ShowMsgPanel : UserControl
    {

        public enum MsgPanelType {  MessageRead,MessageRecv, Error};

        public ShowMsgPanel()
        {
            InitializeComponent();
        }


        string m_strLastCMD = "";
        string m_strLastOrderID = "";
        MsgPanelType m_cpt = MsgPanelType.Error;

        public void initial(string arg_strCMD, MsgPanelType arg_Type)
        {

            m_cpt = arg_Type;
            m_strLastCMD = arg_strCMD;

            switch (m_cpt)
            {
                case MsgPanelType.MessageRecv:
                    if (this.Visible) SoundManager.getInstance().playMsgRecv();
                    break;
            }
            
            LogManager.getInstance().Log("initial DCP:" + arg_Type.ToString());
            this.timer_Timeout.Enabled = true;


            switch (m_cpt)
            {
                case MsgPanelType.MessageRead:

                    this.textBox_Msg.Text = arg_strCMD;
                    TrimMessageEnd();

                    this.button_F1.Text = "返回";
                    this.button_F1.Visible = true;


                    break;
                case MsgPanelType.MessageRecv:

                    this.textBox_Msg.Text = arg_strCMD;
                    TrimMessageEnd();

                    this.button_F1.Text = "返回";
                    this.button_F1.Visible = true;

                    break;
            }

        }

        /// <summary>
        /// 由於派遣地址尾端有經緯度, 因此要清除掉
        /// </summary>
        private void TrimMessageEnd()
        {
            int nIndex = this.textBox_Msg.Text.IndexOf('\t');
            if (nIndex != -1)
            {
                textBox_Msg.Text = textBox_Msg.Text.Split('\t')[0];
            }

        }



        private void timer_Timeout_Tick(object sender, EventArgs e)
        {
            //持續 Beep Beep 叫

            switch (m_cpt)
            {
                case MsgPanelType.MessageRecv:
                    if (this.Visible) SoundManager.getInstance().playMsgRecv();
                    break;
            }

        }

        private void button_F1_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            this.SendToBack();
        }



    }
}
